﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Xml;
using System.IO;

namespace MonitorClient
{
    public class ConfigSetting
    {
        static readonly ConfigSetting instance = new ConfigSetting();
        Config config = null;
        private ConfigSetting()
        {
            XmlSerializer ser = new XmlSerializer(typeof(Config));
            XmlReader reader = XmlReader.Create(new StreamReader(FilePath));
            config = (Config)ser.Deserialize(reader);
        }
        private string FilePath
        {
            get
            {
                string model = typeof(Config).Assembly.GetModules()[0].FullyQualifiedName;
                string directory = Path.GetDirectoryName(model);
                return directory + "\\config.xml";
                //return System.Environment.CurrentDirectory+"\\Monitor\\config.xml";
                //return @"D:\Projects\Wicresoft.WinService\Wicresoft.Task\Monitor\config.xml";
            }
        }
        public static Config LoadConfig()
        {
            return instance.config;
        }
    }
}
